<head>
 <style type="text/css"> 
        input.number { text-align:right; }
 </style>

</head>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#dialog-form').load('<?php echo site_url(); ?>anggota/popup');
		$("#dialog-form").dialog({
			autoOpen: false,
			title: 'Anggota',
			height: 400,
			width: 712,
			modal: true,
			buttons: {
				'OK': function() {
					var chkIdx = $('input:radio:checked').val();
					var aData = popup_table.fnGetData(chkIdx);
					$("#anggotaID").val($("#id"+chkIdx).val());
					$("#anggota").val(aData[0]);
					$("#nama_anggota").val(aData[1]);
					$("#alamat_anggota").val(aData[2]);
					$("#pekerjaan_anggota").val(aData[3]);
					$(this).dialog('close');
				},
				'Batal': function() {
					$(this).dialog('close');
				}
			},
		});

		$('#anggota').focus(function() {
				$('#dialog-form').dialog('open');
			});

	});
	
	var xxx = -1;
	$(document).ready(function() {
	  $.viewMap = {
		'0' : $([]),
		'view1' : $('#view1'),
		'view2' : $('#view2a, #view2b')
	  };

	  $('#viewSelector').change(function() {
		// hide all
		$.each($.viewMap, function() { this.hide(); });
		// show current
		$.viewMap[$(this).val()].show();
		xxx = $(this).val();		
		if(xxx == 'view1'){
			document.getElementById("jenis_agunan").value = '1';			
		}else{
			document.getElementById("jenis_agunan").value = '2';			
		}
	  }).change();
	  
	});

	function updateJatuhTempoHari(ish){
		var d = new Date(document.getElementById("datepicker2").value);
		d.setDate((d.getDate()+parseInt(ish)));
		document.getElementById("datepicker3").value = d.getFullYear()+'-'+
		(d.getMonth()+parseInt(1))
		+'-'+d.getDate();
		document.getElementById("masa_angsuran").value = ish;
	}
	
	function updateJatuhTempoMinggu(ish){
		var d = new Date(document.getElementById("datepicker2").value);
		d.setDate((d.getDate()+parseInt(ish*7)));
		document.getElementById("datepicker3").value = d.getFullYear()+'-'+(d.getMonth()+parseInt(1))+'-'+d.getDate();
		document.getElementById("masa_angsuran").value = ish;
	}
	
	function updateJatuhTempoBulan(ish){
		var d = new Date(document.getElementById("datepicker2").value);
		d.setMonth((d.getMonth()+parseInt(ish)));
		document.getElementById("datepicker3").value = d.getFullYear()+'-'+(d.getMonth()+parseInt(1))+'-'+d.getDate();
		document.getElementById("masa_angsuran").value = ish;
	}
	
	function hitungAngsuranPokokfromMasa(ish){
		var plafond = document.getElementById("plafond").value;
		var angsuran_pokok = unFormatIDR(plafond) / ish;
		document.getElementById("angsuran_pokok").value = formatIDR(angsuran_pokok);
		var bunga_persen = document.getElementById("bunga_persen").value;
		hitungAngsuranBunga(bunga_persen);
	}
	
	function hitungAngsuranPokok(ish){
		var masa = document.getElementById("masa_angsuran").value;
		var angsuran_pokok = ish / masa;
		document.getElementById("angsuran_pokok").value = formatIDR(angsuran_pokok);
		var bunga_persen = document.getElementById("bunga_persen").value;
		hitungAngsuranBunga(bunga_persen);
	}
	
	function hitungAngsuranBunga(ish){
		var masa = document.getElementById("masa_angsuran").value;
		var bunga_persen = ish / 100;
		var angsuran_pokok = document.getElementById("angsuran_pokok").value;
		var plafond = document.getElementById("plafond").value;
		bunga_persen = bunga_persen * unFormatIDR(plafond);
		document.getElementById("angsuran_bunga").value = formatIDR(bunga_persen);
		var total_angsuran = unFormatIDR(angsuran_pokok) + bunga_persen;
		document.getElementById("total_angsuran").value = formatIDR(total_angsuran);
	}
	
</script>

<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<div id="dialog-form"></div>

<?php
	echo form_open('pinjaman/'.$form_act, 'id="pinjaman_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">						  
		<tr>
		<td colspan='5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<?php
		if($pinjaman_data['jenis_pinj']==3){
		
		}else{
			echo form_button(array('id' => 'button-add-harian', 'content' => 'Harian', 'onClick' => "location.href='".site_url()."pinjaman/add'" ));		
			echo form_button(array('id' => 'button-add-mingguan', 'content' => 'Mingguan', 'onClick' => "location.href='".site_url()."pinjaman/add_mingguan'" ));		
			echo form_button(array('id' => 'button-add-bulanan', 'content' => 'Bulanan', 'onClick' => "location.href='".site_url()."pinjaman/add_bulanan'" ));		
			echo form_button(array('id' => 'button-add-gadean', 'content' => 'Gadean', 'onClick' => "location.href='".site_url()."pinjaman/add_gadean'" ));		
			echo form_button(array('id' => 'button-add-p3kum', 'content' => 'P3 KUM', 'onClick' => "location.href='".site_url()."pinjaman/add_p3kum'" ));
		}
		?></td>
		</tr>
		<tr>
						
		</tr>
		<tr>
			<th><?php echo form_label('Rek Pinjaman **','no_rekening'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_rekening';
					
					$data_kode = '510';
					$data_ksm = 'KSM';
					$data_kdbln = 'BLN';
					$data_bln = toRmw(date("m"));					
					$data_thn = date("y");
					$data_id = '0001';
					
					if($act=='add')
					{ 
						if($new_id == ''){					
							//$data['value'] = $data_kode.'.'.$data_bln.'.'.$data_thn.'.'.$data_id;
							$data['value'] = $data_id.'/'.$data_ksm.'/'.$data_kdbln.'/'.$data_kode.'/'.$data_bln.'/'.$data_thn;
						}else{						
							//$data['value'] = 'SP' . formatIdpinjaman(substr($new_id->no_rekening, 2) + 1);
							//echo substr($new_id->no_rekening,7,2).substr($new_id->no_rekening,4,2).'<'.$data_thn.$data_bln;
							//0001/KSM/BLN/510/07/12
							if (substr($new_id->no_rekening,-2).fromRmw(getRmw($new_id->no_rekening)) < ($data_thn.fromRmw($data_bln))) {
								$data_id = '0001';
							}else{						
								$data_id = formatIdpinjaman(substr($new_id->no_rekening,0,4) + 1);
							}
							//$data['value'] = $data_kode.'.'.$data_bln.'.'.$data_thn.'.'.$data_id;
							$data['value'] = $data_id.'/'.$data_ksm.'/'.$data_kdbln.'/'.$data_kode.'/'.$data_bln.'/'.$data_thn;
						}						
					}else{
						$data['value'] = (set_value('no_rekening')) ? set_value('no_rekening') : $pinjaman_data['no_rekening'];
					}
					
					$data['title'] = "no rekening tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='no_rekening' name='no_rekening' size='30' class='required' value='$data[value]'/>";
				?>
			</td>
			<th><?php echo form_label('Periode','periode'); ?></th>
			<td>
				
					<?php
					$data['name'] = $data['id'] = 'periode';
					$data['value'] = (set_value('periode')) ? set_value('periode') : $pinjaman_data['periode'];
					$data['title'] = "Periode tidak boleh kosong";
					//echo form_input($data);
					if($data['value']==""){
						$data['value'] = 1;
					}
				echo "<input type=text id='periode' name='periode' size='5' value='$data[value]' align=right onkeypress='return numbersonly(this, event)' onBlur='updateJatuhTempoBulan(this.value);' class='required' /> bulan";
				?>
								
			</td>
		</tr>
		<tr>
			<th colspan='2'>** Rek Pinjaman jangan diubah (otomatis dibuat) </th>
			<th>
				<?php echo form_label('Keperluan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $pinjaman_data['keterangan'];
					unset($data['title']);
					echo "<input id='keterangan' name='keterangan' size='50' value='$data[value]' />";	
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Tanggal','tgl_mulai'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_mulai';
					//$data['id'] = 'datepicker2';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_mulai')) ? set_value('tgl_mulai') : $pinjaman_data['tgl_mulai'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker2' name='tgl_mulai' size='15' class='required' value='$data[value]' /> *(yyyy-mm-dd)";
				?>
			</td>	
			
		</tr>
		
		<tr>
			<th colspan='2'><h4>Data Anggota</h4>
			</th>
			<th><h4>Data Pinjaman</h4></th>
			<td>
			</td>
		</tr>
		
		<tr>
			<th><?php echo form_label('ID Anggota *','anggota'); ?></th>
			<td>
				<?php 
					echo form_hidden('anggotaID',$pinjaman_data['anggota_id']);

					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $pinjaman_data['anggota_id'];
					$data['title'] = "Anggota tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='anggota' name='anggota' size='25' class='required' value='$data[value]' />";
				?>
			</td>	
			<th><?php echo form_label('Biaya Administrasi','biaya'); ?></th>
			<td>
				<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='biaya' name='biaya' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						
						<?php
					}else{					
						$data['value'] = (set_value('biaya')) ? set_value('biaya') : $pinjaman_data['biaya'];
						?>
						<input type=text id='biaya' name='biaya' size='30' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						<?php
						
					}
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Nama','nama_anggota'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nama_anggota';
					$data['value'] = (set_value('nama_anggota')) ? set_value('nama_anggota') : $pinjaman_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					
					echo "<input id='nama_anggota' name='nama_anggota' size='25' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>	
			<th><?php echo form_label('Masa Angsuran','masa_angsuran'); ?></th>
			<td>
				<?php 
					/*
					$data['name'] = $data['id'] = 'masa_angsuran';
					$data['value'] = (set_value('masa_angsuran')) ? set_value('masa_angsuran') : $pinjaman_data['masa_angsuran'];
					unset($data['title']);	
					//echo form_input($data);
					if($data['value']==""){
						$data['value'] = 1;
					}
					echo "<input id='masa_angsuran
					' name='masa_angsuran' size='5' class='required number' value='$data[value]' /> kali";
					hitungAngsuranPokok */
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='masa_angsuran' name='masa_angsuran' size='5' value='1' align=right onkeypress='return numbersonly(this, event)' onBlur='hitungAngsuranPokokfromMasa(this.value);' class='required' maxlength='20'> kali						
						<?php
					}else{					
						$data['value'] = (set_value('masa_angsuran')) ? set_value('masa_angsuran') : $pinjaman_data['masa_angsuran'];
						?>
						<input type=text id='masa_angsuran' name='masa_angsuran' size='5' value='<?php echo $data['value']; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='hitungAngsuranPokokfromMasa(this.value);' class='required' maxlength='20'> kali
						<?php
						
					}
				?>
			</td>		
		</tr>
		<tr>
			<th><?php echo form_label('Alamat','alamat_anggota'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'alamat_anggota';
					$data['value'] = (set_value('alamat_anggota')) ? set_value('alamat_anggota') : $pinjaman_data['alamat'];					
					echo "<textarea id='alamat_anggota' name='alamat_anggota' cols='30' rows='3' class='required'  disabled='1'>$data[value]</textarea>";
				?>
			</td>	
			<th><?php echo form_label('Tanggal Jatuh Tempo','tgl_jatuh_tempo'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_jatuh_tempo';
					//$data['id'] = 'datepicker3';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_jatuh_tempo')) ? set_value('tgl_jatuh_tempo') : $pinjaman_data['tgl_jatuh_tempo'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker3' name='tgl_jatuh_tempo' size='15' class='required' value='$data[value]' /> *(yyyy-mm-dd)";
				?>
			</td>	
		</tr>
		<tr>
			<th><?php echo form_label('Pekerjaan','pekerjaan_anggota'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'pekerjaan_anggota';
					$data['value'] = (set_value('pekerjaan_anggota')) ? set_value('pekerjaan_anggota') : $pinjaman_data['pekerjaan'];
					echo "<input id='pekerjaan_anggota' name='pekerjaan_anggota' size='25' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>	
			
			<th><?php echo form_label('Plafond','plafond'); ?></th>
			<td>
				<?php 
					/*
					$data['name'] = $data['id'] = 'plafond';
					$data['value'] = (set_value('plafond')) ? set_value('plafond') : $pinjaman_data['plafond'];
					//unset($data['title']);
					echo "<input id='plafond' name='plafond' size='30' class='required number' value='$data[value]'/>";	
					*/
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='plafond' name='plafond' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value); hitungAngsuranPokok(unFormatIDR(this.value));' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						
						<?php
					}else{					
						$data['value'] = (set_value('plafond')) ? set_value('plafond') : $pinjaman_data['plafond'];
						?>
						<input type=text id='plafond' name='plafond' size='30' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value); hitungAngsuranPokok(unFormatIDR(this.value));' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						<?php
						
					}
				?>
			</td>
		</tr>
				
		<tr>
			<th><h4><font color='blue'>Data Agunan</font></h4></th>
			<td><br><br>
			</td>
			<th><?php echo form_label('Bunga','bunga_persen'); ?></th>
			<td>
				<?php 
				/*
					$data['name'] = $data['id'] = 'bunga_persen';
					$data['value'] = (set_value('bunga_persen')) ? set_value('bunga_persen') : $pinjaman_data['bunga_persen'];
					//unset($data['title']);
					echo "<input id='bunga_persen' name='bunga_persen' size='2' class='required number' value='$data[value]' maxlength='3' />% - "; 
					$data['name'] = $data['id'] = 'bunga';
					$data['value'] = (set_value('bunga')) ? set_value('bunga') : $pinjaman_data['bunga'];
					echo "<input id='bunga' name='bunga' size='20' class='required number' value='$data[value]' />";	
					 */
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='bunga_persen' name='bunga_persen' size='5' value='1' align=right onkeypress='return numbersonly(this, event)' onBlur='hitungAngsuranBunga(this.value);' class='required' maxlength='20'> %
						<?php
						//$data['value'] = 0;
						?>
						<!--
						<input type=text id='plafond' name='plafond' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value); hitungAngsuranPokok(unFormatIDR(this.value));' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						-->
						<?php
					}else{					
						$data['value'] = (set_value('bunga_persen')) ? set_value('bunga_persen') : $pinjaman_data['bunga_persen'];
						?>					
						<input type=text id='bunga_persen' name='bunga_persen' size='5' value='<?php echo $data['value']; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='hitungAngsuranBunga(this.value);' class='required' maxlength='20'> %
						<?php
						//$data['value'] = (set_value('plafond')) ? set_value('plafond') : $pinjaman_data['plafond'];
						?>
						<!--
						<input type=text id='plafond' name='plafond' size='30' value='<?php //echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						-->
						<?php
						
					}
				?>
			</td>
		</tr>
		
		
		<tr>
			<th align='top' rowspan='30' colspan='2'>			
			Jenis Agunan
				<select id="viewSelector">   
			   <option value="view1">Kendaraan bermotor</option>
			   <option value="view2">Sertifikat rumah</option>
				</select>
				<br>
				<?php 
								$data['name'] = $data['id'] = 'jenis_agunan';
								$data['value'] = (set_value('jenis_agunan')) ? set_value('jenis_agunan') : $pinjaman_data['jenis_agunan'];
								unset($data['title']);
								//echo "<input id='jenis_agunan' name='jenis_agunan' size='1' value='$data[value]' />";
								echo "<input type=hidden id='jenis_pinj' name='jenis_pinj' size='1' value='3' />";
							?>				
				<div id="view1">  
					<table>
					<tr>
						<th>
							<?php echo form_label('Nama Pemilik','nama_pemilik'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='nama_pemilik' name='nama_pemilik' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('nama_pemilik')) ? set_value('nama_pemilik') : $pinjaman_data['nama_pemilik'];
						?>
						<input type=text id='nama_pemilik' name='nama_pemilik' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						
					}
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Alamat','alamat_pemilik'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<textarea id='alamat_pemilik' name='alamat_pemilik' rows='3' cols='30' ></textarea>		
						<?php
					}else{					
						$data['value'] = (set_value('alamat_pemilik')) ? set_value('alamat_pemilik') : $pinjaman_data['alamat_pemilik'];
						echo "<textarea id='alamat_pemilik' name='alamat_pemilik' cols='30' rows='3' >$data[value]</textarea>";						
					}  ?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nomor BPKP','no_bpkb'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'no_bpkb';
								$data['value'] = (set_value('no_bpkb')) ? set_value('no_bpkb') : $pinjaman_data['no_bpkb'];
								unset($data['title']);
								echo "<input id='no_bpkb' name='no_bpkb' size='20' value='$data[value]' />";	
							?>
						</td>					
						
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nomor Reg','no_reg'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'no_reg';
								$data['value'] = (set_value('no_reg')) ? set_value('no_reg') : $pinjaman_data['no_reg'];
								unset($data['title']);
								echo "<input id='no_reg' name='no_reg' size='40' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nomor Polisi','no_polisi'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'no_polisi';
								$data['value'] = (set_value('no_polisi')) ? set_value('no_polisi') : $pinjaman_data['no_polisi'];
								unset($data['title']);
								echo "<input id='no_polisi' name='no_polisi' size='10' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Merk','merk'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'merk';
								$data['value'] = (set_value('merk')) ? set_value('merk') : $pinjaman_data['merk'];
								unset($data['title']);
								echo "<input id='merk' name='merk' size='25' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Type','type'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'type';
								$data['value'] = (set_value('type')) ? set_value('type') : $pinjaman_data['type'];
								unset($data['title']);
								echo "<input id='type' name='type' size='25' value='$data[value]' />";
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Jenis','jenis'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'jenis';
								$data['value'] = (set_value('jenis')) ? set_value('jenis') : $pinjaman_data['jenis'];
								unset($data['title']);
								echo "<input id='jenis' name='jenis' size='25' value='$data[value]' />";
							?>
						</td>
					</tr>					
					<tr>
						<th>
							<?php echo form_label('Model','model'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'model';
								$data['value'] = (set_value('model')) ? set_value('model') : $pinjaman_data['model'];
								unset($data['title']);
								echo "<input id='model' name='model' size='25' value='$data[value]' />";
							?>
						</td>
					</tr>					
					<tr>
						<th>
							<?php echo form_label('Tahun Pembuatan','tahun_pembuatan'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'tahun_pembuatan';
								$data['value'] = (set_value('tahun_pembuatan')) ? set_value('tahun_pembuatan') : $pinjaman_data['tahun_pembuatan'];
								unset($data['title']);
								echo "<input id='tahun_pembuatan' name='tahun_pembuatan' size='5' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Tahun Perakitan','tahun_perakitan'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'tahun_perakitan';
								$data['value'] = (set_value('tahun_perakitan')) ? set_value('tahun_perakitan') : $pinjaman_data['tahun_perakitan'];
								unset($data['title']);
								echo "<input id='tahun_perakitan' name='tahun_perakitan' size='5' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Isi Silinder','isi_silinder'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'isi_silinder';
								$data['value'] = (set_value('isi_silinder')) ? set_value('isi_silinder') : $pinjaman_data['isi_silinder'];
								unset($data['title']);
								echo "<input id='isi_silinder' name='isi_silinder' size='10' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Warna','warna'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'warna';
								$data['value'] = (set_value('warna')) ? set_value('warna') : $pinjaman_data['warna'];
								unset($data['title']);
								echo "<input id='warna' name='warna' size='5' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nomor Rangka','no_rangka'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'no_rangka';
								$data['value'] = (set_value('no_rangka')) ? set_value('no_rangka') : $pinjaman_data['no_rangka'];
								unset($data['title']);
								echo "<input id='no_rangka' name='no_rangka' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nomor Mesin','no_mesin'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'no_mesin';
								$data['value'] = (set_value('no_mesin')) ? set_value('no_mesin') : $pinjaman_data['no_mesin'];
								unset($data['title']);
								echo "<input id='no_mesin' name='no_mesin' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>					
					<tr>
						<th>
							<?php echo form_label('Jumlah Roda','roda'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'roda';
								$data['value'] = (set_value('roda')) ? set_value('roda') : $pinjaman_data['roda'];
								unset($data['title']);
								echo "<input id='roda' name='roda' size='5' value='$data[value]' />";
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Bahan Bakar','bahan_bakar'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'bahan_bakar';
								$data['value'] = (set_value('bahan_bakar')) ? set_value('bahan_bakar') : $pinjaman_data['bahan_bakar'];
								unset($data['title']);
								echo "<input id='bahan_bakar' name='bahan_bakar' size='30' value='$data[value]' />";
							?>
						</td>
					</tr>
					</table>
				</div>
				<div id="view2a">  					
					<table>
					<tr>
						<th>
							<?php echo form_label('Hak Milik','hak_milik'); ?>
						</th>
						<td>
							<?php
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='hak_milik' name='hak_milik' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('hak_milik')) ? set_value('hak_milik') : $pinjaman_data['hak_milik'];
						?>
						<input type=text id='hak_milik' name='hak_milik' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						
					}
							?>
						</td>
					</tr>		
					<tr>
						<th>
							<?php echo form_label('NIB','nib'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='nib' name='nib' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('nib')) ? set_value('nib') : $pinjaman_data['nib'];
						?>
						<input type=text id='nib' name='nib' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						
					}
							?>
						</td>
					</tr>					
					<tr>
						<th>
							<?php echo form_label('Asal Hak Pemisahan','asal_hak_pemisahan'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'asal_hak_pemisahan';
								$data['value'] = (set_value('asal_hak_pemisahan')) ? set_value('asal_hak_pemisahan') : $pinjaman_data['asal_hak_pemisahan'];
								unset($data['title']);
								echo "<input id='asal_hak_pemisahan' name='asal_hak_pemisahan' size='30' value='$data[value]' />";
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Dasar Pendaftaran','dasar_pendaftaran'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'dasar_pendaftaran';
								$data['value'] = (set_value('dasar_pendaftaran')) ? set_value('dasar_pendaftaran') : $pinjaman_data['dasar_pendaftaran'];
								unset($data['title']);
								echo "<input id='dasar_pendaftaran' name='dasar_pendaftaran' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Surat ukur','surat_ukur'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'surat_ukur';
								$data['value'] = (set_value('surat_ukur')) ? set_value('surat_ukur') : $pinjaman_data['surat_ukur'];
								unset($data['title']);
								echo "<input id='surat_ukur' name='surat_ukur' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Luas','luas'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'luas';
								$data['value'] = (set_value('luas')) ? set_value('luas') : $pinjaman_data['luas'];
								unset($data['title']);
								echo "<input id='luas' name='luas' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Nama Pemegang Hak','pemegang_hak'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'pemegang_hak';
								$data['value'] = (set_value('pemegang_hak')) ? set_value('pemegang_hak') : $pinjaman_data['pemegang_hak'];
								unset($data['title']);
								echo "<input id='pemegang_hak' name='pemegang_hak' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
					<th><?php echo form_label('Tanggal Lahir','tgl_lahir'); ?></th>
					<td>
						<?php 
							$data['name'] = 'tgl_lahir';
							if($act=='add')
							{ 
								$data['value'] = date("Y-m-d");;
							}else{					
								$data['value'] = (set_value('tgl_lahir')) ? set_value('tgl_lahir') : $pinjaman_data['tgl_lahir'];
							}
							$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";						
							echo "<input id='datepickerlahir2' name='tgl_lahir' size='15' class='required' value='$data[value]' /> *(yyyy-mm-dd)";
						?>
					</td>	
					</tr>
					<tr>
						<th>
							<?php echo form_label('Pembukuan','pembukuan'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'pembukuan';
								$data['value'] = (set_value('pembukuan')) ? set_value('pembukuan') : $pinjaman_data['pembukuan'];
								unset($data['title']);
								echo "<input id='pembukuan' name='pembukuan' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Sertifikat','sertifikat'); ?>
						</th>
						<td>
							<?php 
								$data['name'] = $data['id'] = 'sertifikat';
								$data['value'] = (set_value('sertifikat')) ? set_value('sertifikat') : $pinjaman_data['sertifikat'];
								unset($data['title']);
								echo "<input id='sertifikat' name='sertifikat' size='30' value='$data[value]' />";	
							?>
						</td>
					</tr>
					</table>
				</div>
				
			</th>
		</tr>
		<tr>
			
			<th><?php echo form_label('Angsuran Pokok','angsuran_pokok'); ?></th>
			<td>
				<?php 
					/*
					$data['name'] = $data['id'] = 'angsuran_pokok';
					$data['value'] = (set_value('angsuran_pokok')) ? set_value('angsuran_pokok') : $pinjaman_data['angsuran_pokok'];
					//unset($data['title']);
					echo "<input id='angsuran_pokok' name='angsuran_pokok' size='30' class='required number' value='$data[value]'/>";	
					*/
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='angsuran_pokok' name='angsuran_pokok' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						
						<?php
					}else{					
						$data['value'] = (set_value('angsuran_pokok')) ? set_value('angsuran_pokok') : $pinjaman_data['angsuran_pokok'];
						?>
						<input type=text id='angsuran_pokok' name='angsuran_pokok' size='30' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						<?php						
					}
				?>
			</td>
						
		</tr>
		<tr>			
			<th><?php echo form_label('Angsuran Bunga','angsuran_bunga'); ?></th>
			<td>
				<?php 
				/*
					$data['name'] = $data['id'] = 'angsuran_bunga';
					$data['value'] = (set_value('angsuran_bunga')) ? set_value('angsuran_bunga') : $pinjaman_data['angsuran_bunga'];
					//unset($data['title']);
					echo "<input id='angsuran_bunga' name='angsuran_bunga' size='30' class='required 
					number' value='$data[value]'/>";	
				*/
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='angsuran_bunga' name='angsuran_bunga' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20' >
						
						<?php
					}else{					
						$data['value'] = (set_value('angsuran_bunga')) ? set_value('angsuran_bunga') : $pinjaman_data['angsuran_bunga'];
						?>
						<input type=text id='angsuran_bunga' name='angsuran_bunga' size='30' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20' >
						<?php						
					}
				?>
			</td>
		</tr>
		
		<tr>
			<th><?php echo form_label('Total Angsuran','total_angsuran'); ?></th>
			<td>
				<?php 
				/*
					$data['name'] = $data['id'] = 'total_angsuran';
					$data['value'] = (set_value('total_angsuran')) ? set_value('total_angsuran') : $pinjaman_data['total_angsuran'];
					//unset($data['title']);
					echo "<input id='total_angsuran' name='total_angsuran' size='30' class='required number' value='$data[value]'/>";	
				*/
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='total_angsuran' name='total_angsuran' size='30' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20' >
						
						<?php
					}else{					
						$data['value'] = (set_value('total_angsuran')) ? set_value('total_angsuran') : $pinjaman_data['total_angsuran'];
						?>
						<input type=text id='total_angsuran' name='total_angsuran' size='30' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20' >
						<?php						
					}
				?>
			</td>			
		</tr>
		<tr>
			<th><h4><font color='blue'>Data Ahli Waris</font></h4></th>
			<td>
				
			</td>			
		</tr>
		<tr>
			<th colspan='2'><font color='red'>Dalam hal apabila Peminjam meninggal dunia maka segala kewajibannya beralih sepenuhnya kepada : </font></th>
						
		</tr>
					<tr>
						<th>
							<?php echo form_label('Nama ','nama_waris'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='nama_waris' name='nama_waris' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('nama_waris')) ? set_value('nama_waris') : $pinjaman_data['nama_waris'];
						?>
						<input type=text id='nama_waris' name='nama_waris' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						
					}
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Tempat Lahir','tempat_lahir_waris'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='tempat_lahir_waris' name='tempat_lahir_waris' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('tempat_lahir_waris')) ? set_value('tempat_lahir_waris') : $pinjaman_data['tempat_lahir_waris'];
						?>
						<input type=text id='tempat_lahir_waris' name='tempat_lahir_waris' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						}
							?>
						</td>
					</tr>
					<tr>
					<th><?php echo form_label('Tanggal Lahir','tgl_lahir_waris'); ?></th>
					<td>
						<?php 
							$data['name'] = 'tgl_lahir_waris';
							if($act=='add')
							{ 
								$data['value'] = date("Y-m-d");;
							}else{					
								$data['value'] = (set_value('tgl_lahir_waris')) ? set_value('tgl_lahir_waris') : $pinjaman_data['tgl_lahir_waris'];
							}
							$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
							//echo form_input($data);
							echo "<input id='datepicker' name='tgl_lahir_waris' size='15' class='required' value='$data[value]' /> *(yyyy-mm-dd)";
						?>
					</td>	
					</tr>
					
					<tr>
						<th>
							<?php echo form_label('Pekerjaan','pekerjaan_waris'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='pekerjaan_waris' name='pekerjaan_waris' size='30' value=''>		
						<?php
					}else{					
						$data['value'] = (set_value('pekerjaan_waris')) ? set_value('pekerjaan_waris') : $pinjaman_data['pekerjaan_waris'];
						?>
						<input type=text id='pekerjaan_waris' name='pekerjaan_waris' size='30' value='<?php echo $data['value']; ?>' >
						<?php
						}
							?>
						</td>
					</tr>
					<tr>
						<th>
							<?php echo form_label('Alamat','alamat_waris'); ?>
						</th>
						<td>
							<?php 
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<textarea id='alamat_waris' name='alamat_waris' rows='3' cols='30' ></textarea>		
						<?php
					}else{					
						$data['value'] = (set_value('alamat_waris')) ? set_value('alamat_waris') : $pinjaman_data['alamat_waris'];
						echo "<textarea id='alamat_waris' name='alamat_waris' cols='30' rows='3' >$data[value]</textarea>";						
					}  ?>
						</td>
					</tr>	
		
			
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."pinjaman'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."pinjaman'" ));
			}
		?>				
	</div>
	
<?php echo form_close(); ?>

</div>

<script type='text/javascript'>
	//Validasi di client
		
	$(document).ready(function(){
		$("#pinjaman_form").validate({
			messages: {
					biaya: " Biaya harus diisi"
			}
		});
    });
  
	/*
	$(document).ready(function()
	{
		$('#pinjaman_form').validate({
			errorLabelContainer: "#error",
			wrapper: "li",
			rules: 
			{
				nama: "required",
				anggota: "required",
				tgl_mulai: "dateISO",
				biaya: "integer""
			}
		});
	});
	*/
</script>
<?php
function getRmw($id){
	$id = substr($id,17);
	$id = substr($id, 0, -3); 	
	return $id;
}

function right($value, $count){
    return substr($value, ($count*-1));
}
function toRmw($id){
	if($id == '01'){
		return 'I';
	}else if($id == '02'){
		return 'II';
	}else if($id == '03'){
		return 'III';
	}else if($id == '04'){
		return 'IV';
	}else if($id == '05'){
		return 'V';
	}else if($id == '06'){
		return 'VI';
	}else if($id == '07'){
		return 'VII';
	}else if($id == '08'){
		return 'VIII';
	}else if($id == '09'){
		return 'IX';
	}else if($id == '10'){
		return 'X';
	}else if($id == '11'){
		return 'XI';
	}else if($id == '12'){
		return 'XII';
	}
}

function fromRmw($id){
	if($id == 'I'){
		return '01';
	}else if($id == 'II'){
		return '02';
	}else if($id == 'III'){
		return '03';
	}else if($id == 'IV'){
		return '04';
	}else if($id == 'V'){
		return '05';
	}else if($id == 'VI'){
		return '06';
	}else if($id == 'VII'){
		return '07';
	}else if($id == 'VIII'){
		return '08';
	}else if($id == 'IX'){
		return '09';
	}else if($id == 'X'){
		return '10';
	}else if($id == 'XI'){
		return '11';
	}else if($id == 'XII'){
		return '12';
	}
}	
function formatIdpinjaman($id){		
		if (strlen($id) == 1)
		{
			return '000' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 3)
		{
			return '0' . $id;
		}
		else {
			return $id;
		}
}
?>